/**
 * Created by quxiangqian on 2018/6/17.
 */
import {ToolTip} from "../control/ToolTip";
export class TextField extends React.Component {
    state={
        value:"",
        error:false,
        message:""
    }
    onChange=(e,item)=>{
        item.value=e.target.value;
        this.setState({value:e.target.value});
    }

    showError=(message)=>{
        this.state.error=true;

        this.setState({error:true,message:message});
    }

    default=()=>{
        this.setState({error:false});
    }

    render(){
        let item= this.props.bind[this.props.name];

        item.showError=this.showError;
        item.default=this.default;

        if(item.value){
            this.state.value=item.value;
        }
        let style={}
        let tem=<input type="text" {...this.props} ref="t"  name={this.props.name} value={this.state.value} onChange={(e)=>this.onChange(e,item)} className="form-control"/>
        if(this.state.error===true){
            style.borderColor="red";
            tem=<ToolTip text={this.state.message} css="error" pos="right"><input style={style} type="text" {...this.props} ref="t"  name={this.props.name} value={this.state.value} onChange={(e)=>this.onChange(e,item)} className="form-control"/></ToolTip>
        }
        return tem;
    }
}